package lab.gene.action;

import java.util.Date;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lab.gene.service.impl.GeneTS559ServiceImpl;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;

public class UpdateGeneTS559Action extends ActionSupport implements ServletResponseAware, ServletRequestAware {
	
	private static final long serialVersionUID = 1L;
	private Date recordDate = null;
	private String comments = null;
	private String geneName = null;
	private String type = null;
	
	protected HttpServletResponse servletResponse;  
	@Override   
	public void setServletResponse(HttpServletResponse servletResponse) {   
		this.servletResponse = servletResponse;   
	}   
	
	protected HttpServletRequest servletRequest;   
	@Override   
	public void setServletRequest(HttpServletRequest servletRequest) {   
		this.servletRequest = servletRequest;   
	}
	
	public String execute()  {
		String result = null;
		
		Cookie[] cookies = servletRequest.getCookies();
		String cookieName = "LabUser";
		String userName = null;
		if (cookies != null) {
			for (int i = 0; i < cookies.length; i++) {
				if (cookies[i].getName().equals(cookieName)) {
					userName = cookies[i].getValue();
					break;
				}
			}
		}

		GeneTS559ServiceImpl service = new GeneTS559ServiceImpl();
		service.addGeneTS559(geneName, type, userName, comments, recordDate);
		
		switch (type) {
		case "B":
			result = "successB";
			break;
		case "C":
			result = "successC";
			break;
		case "D":
			result = "successD";
			break;
		}
		return result;
	}
	
	public Date getRecordDate() {
		return recordDate;
	}
	public void setRecordDate(Date recordDate) {
		this.recordDate = recordDate;
	}
	public String getComments() {
		return comments;
	}
	public void setComments(String comments) {
		this.comments = comments;
	}
	public String getGeneName() {
		return geneName;
	}
	public void setGeneName(String geneName) {
		this.geneName = geneName;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	} 
	
	

}
